package com.fs.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fs.mapper.InventoryDetail;
import com.fs.pojo.WhInvInventory;
import com.fs.pojo.WhInvInventoryDetail;
import com.fs.service.InventoryDetailService;
import com.fs.service.InventoryService;
import com.fs.vo.Condition;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author yyds
 * @fileName InventoryDetailServiceImpl
 * @date 2024/10/11 19:34
 * @description 盘点明细服务
 **/
@Service
public class InventoryDetailServiceImpl implements InventoryDetailService {
    @Resource
    private InventoryDetail inventoryDetail;

    /**
     * 分页按盘点单查询盘点明细
     *
     * @param condition
     * @return
     */
    @Override
    public Page<WhInvInventoryDetail> selectDetailById(Condition<WhInvInventoryDetail> condition) {
        Page<WhInvInventoryDetail> page = new Page<>(condition.getPage(), condition.getCount());
        LambdaQueryWrapper<WhInvInventoryDetail> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(condition.getSearch().getInventoryCountId() > 0, WhInvInventoryDetail::getInventoryCountId, condition.getSearch().getInventoryCountId());
        inventoryDetail.selectPage(page, wrapper);
        return page;
    }

    /**
     * 新增盘点明细表
     *
     * @param condition
     * @return
     */

    @Override
    public Boolean addDetail(Condition<WhInvInventoryDetail> condition) {
        return inventoryDetail.insert(condition.getSearch()) > 0;
    }

    /**
     * 根据盘点明细编号删除
     *
     * @param id
     * @return
     */
    @Override
    public Boolean deleteDetail(Integer id) {
        LambdaQueryWrapper<WhInvInventoryDetail> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(WhInvInventoryDetail::getInventoryDetailId, id);
        return inventoryDetail.delete(wrapper) > 0;
    }

    /**
     * 根据盘点单号批量删除盘点明细
     *
     * @param id
     * @return
     */
    @Override
    public Boolean deleteDetailByInventory(Integer id) {
        LambdaQueryWrapper<WhInvInventoryDetail> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(WhInvInventoryDetail::getInventoryCountId, id);
        return inventoryDetail.delete(wrapper) > 0;
    }

    /**
     * 根据根据盘点明细单编号修改
     *
     * @param condition
     * @return
     */
    @Override
    public Boolean updateDetail(Condition<WhInvInventoryDetail> condition) {
        return inventoryDetail.updateById(condition.getSearch()) > 0;
    }

    /**
     * 根据ID获取对象
     *
     * @param id
     * @return
     */
    @Override
    public WhInvInventoryDetail selectById(Integer id) {
        return inventoryDetail.selectById(id);
    }
}
